const BaseUrlD = require('./confing.js')

//网络请求的封装函数
//url, data, header, method, success, fail, complete
function netWork(obj = {}) {
     // data.opeid = "xzzz" //直接取缓存中的id


     wx.showToast({
          title: '加载中',
          icon: 'success',
          duration: 2000

     })
     wx.request({
          url: BaseUrlD.BaseUrl + obj.url, //请求地址
          data: obj.data || {}, //请求参数 data || {}
          header: {
               "content-type": obj.header || obj.method == "POST" ?
                    'application/x-www-form-urlencoded' : 'application/json'
          }, //请求头
          method: obj.method, //请求方法
          dataType: 'json',
          responseType: 'text',
          success: function(res) {
               if (typeof obj.success == "function") {
                    obj.success(res)
               }
          },
          fail: function(err) {
               wx.showToast({
                    title: '你的网络不给力',
                    icon: 'none',
                    duration: 2000
               })
               obj.fail(err)
          },
          complete: function(res) {
               if (typeof obj.complete == "function") {
                    obj.complete(res)
               }

          }

     })
}
module.exports = {
     netWork
}